
/* GCSx
** DEFINE.H
**
** General defines- menu commands, config options, constants, debug levels,
**  file types, etc. (separated from modules that can otherwise be generic)
*/

/*****************************************************************************
** Copyright (C) 2003-2006 Janson
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
** 
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
*****************************************************************************/

#ifndef __GCSx_DEFINE_H_
#define __GCSx_DEFINE_H_

// Menu/etc commands
enum {
    // Special commands for passing events to listview handling functions
    LV_LCLICK = -100, // Left click
    LV_RCLICK, // Includes popup-menu access key
    LV_SELECT, // Includes double-click, space, enter
    LV_DELETE, // Includes backspace
    LV_MOVE, // Whenever an item becomes selected, in addition to any other event
    
    // Special commands for menu creation (still negative values)
    MENU_SUB,
    MENU_SEP,
    
    // Release of the last command key being held
    CMD_RELEASE,
    
    // Dummy command
    NO_COMMAND = 0,

    // Standard editor/frontend menu commands
    // Assigned static values as they should not ever
    // change, for upwards compatibility (configuration/shortcuts)
    FILE_NEW = 1,
    // (not simply FILE_OPEN due to symbol conflict on Windows platform)
    FILE_OPENEXIST = 61,
    FILE_SAVE = 58,
    FILE_SAVEAS = 62,
    FILE_CLOSE = 59,
    FILE_SAVEALL = 60,
    FILE_CLOSEALL = 2,
    FILE_EXIT = 3,
    FILE_QUIT = 70,
    FILE_EDITOR = 68,
    FILE_RETURNGAME = 98,
    FILE_CLOSEGAME = 99,
    CONFIG_RESOLUTION = 4,
    WINDOW_NEXT = 6,
    WINDOW_PREV = 7,
    WINDOW_CLOSE = 8,
    WINDOW_MIN = 9,
    WINDOW_MAX = 10,
    WINDOW_SWITCHPANEL = 11,
    WINDOW_TILEHORIZ = 93,
    WINDOW_TILEVERT = 94,
    WINDOW_CASCADE = 95,
    WINDOW_CLOSEALL = 96,
    WINDOW_CLOSEALLBUT = 97,
    TOOLS_CHOOSE = 13,
    TOOLS_CHOOSER = 65,
    TOOLS_PEN = 14,
    TOOLS_LINE = 15,
    TOOLS_RECT = 16,
    TOOLS_RECTFILL = 17,
    TOOLS_ELLIPSE = 18,
    TOOLS_ELLIPSEFILL = 19,
    TOOLS_FILL = 20,
    TOOLS_SELECT = 21,
    TOOLS_SELECTELLIPSE = 22,
    TOOLS_WAND = 23,
    TOOLS_DROPPER = 24,
    TOOLS_PLACEITEM = 75,
    TOOLS_PLACESERIES = 92,
    TOOLS_SELECTITEM = 76,
    TOOLS_SELECTDRAG = 25, // Not officially a tool, but used internally
    TOOLS_SELECTITEMDRAG = 91, // Not officially a tool, but used internally
    TOOLS_GLYPHWIDTHDRAG = 63, // Not officially a tool, but used internally
    TOOLS_SETTINGS = 26,
    TOOLS_BLENDUP = 27,
    TOOLS_BLENDDOWN = 28,
    TOOLS_TOLERANCEUP = 29,
    TOOLS_TOLERANCEDOWN = 30,
    TOOLS_ANTIALIAS = 31,
    TOOLS_CONTIGUOUS = 85,
    TOOLS_NEXTCOLOR = 32,
    TOOLS_PREVCOLOR = 33,
    TOOLS_EDITCOLOR = 34,
    TOOLS_NEXTIMAGE = 89,
    TOOLS_PREVIMAGE = 90,
    MODE_EDITTILES = 86,
    MODE_EDITCOLLISION = 87,
    MODE_EDITASSIGN = 88,
    EDIT_SELECTALL = 35,
    EDIT_DESELECTALL = 36,
    EDIT_DELETE = 37,
    EDIT_CUT = 38,
    EDIT_COPY = 39,
    EDIT_PASTE = 40,
    EDIT_UNDO = 41,
    EDIT_REDO = 42,
    EDIT_FLIP = 43,
    EDIT_MIRROR = 44,
    EDIT_SIZEROTATE = 45,
    EDIT_GRADIENT = 46,
    EDIT_COLORIZE = 47,
    EDIT_FILTER = 48,
    EDIT_SETGLYPHWIDTH = 64,
    EDIT_MOVEUP = 81,
    EDIT_MOVEDOWN = 82,
    EDIT_MOVETOP = 83,
    EDIT_MOVEBOTTOM = 84,
    NEW_ANIM = 100,
    NEW_FONT = 101,
    NEW_LIBRARY = 102,
    NEW_IMAGE = 103,
    NEW_NOTES = 104,
    NEW_SCENE = 105,
    NEW_SCRIPT = 106,
    NEW_IMPORT_IMAGE = 107,
    NEW_IMPORT_FONT = 108,
    NEW_FOLDER = 109, // Last code used
    NEW_LAYER = 71,
    VIEW_BROWSER = 5,
    VIEW_CONSOLE = 66,
    VIEW_ZOOMIN = 49,
    VIEW_ZOOMOUT = 50,
    VIEW_PREV = 51,
    VIEW_NEXT = 52,
    VIEW_DOTS_CHOOSE = 53,
    VIEW_DOTS_NONE = 54,
    VIEW_DOTS_TRANS = 55,
    VIEW_DOTS_ALPHA = 56,
    VIEW_GRID = 57,
    VIEW_TOOLPANEL = 12,
    VIEW_TOOLBAR = 67,
    VIEW_ALLLAYER = 72,
    VIEW_DIMLAYER = 73,
    VIEW_NOLAYER = 74,
    VIEW_OUTLINE_CHOOSE = 77,
    VIEW_OUTLINE_NONE = 78,
    VIEW_OUTLINE_NORMAL = 79,
    VIEW_OUTLINE_HANDLE = 80,
    MENU_HELP_INDEX = 69,
};

// Mins and maxes
// * marks those that are currently arbitrary
// Others have a specific reason for the limit
enum {
    MAX_TILES = 65535,
    MAX_COLLMAPS = 2046, // (11 bits in layer data, minus allon/alloff codes)
    MIN_TILESIZE = 4, // * setting this to 1 breaks a couple things in editor like cursors
    MAX_TILESIZE = 256, // *
    MAX_LAYERS = 32,
    MAX_LAYERTILESIZE = 32767, // So multiplying together to get size fits in a signed int
    MAX_ANIMGROUP = 32767, // * Maximum animation sequences
    MIN_SPRITESIZE = 4, // *
    MAX_SPRITESIZE = 1024, // *
    MAX_ANIMCOMP = 255, // * Maximum components in an animation frame
    MAX_ANIMFRAME = 255, // * Maximum frames in an animation sequence
    // This restriction is due to crashes that happen with longer text lines
    // in font routines, etc. This seems to be ok up to font sizes of around 30-40.
    // Not a hard and fast restriction- a couple chars over shouldn't hurt.
    // @TODO: Still might want to put some additional checks/safeguards in once
    // font size selection is implemented.
    MAX_LINELENGTH = 500, // Maximum length of a text line (editbox, etc.)
};

// Debug levels
#define DEBUG_VERSION    0
#define DEBUG_VIDEO  0
#define DEBUG_FATALERROR 0
#define DEBUG_UNDO       1
#define DEBUG_COMPILE    2
#define DEBUG_TOKENIZE   4
#define DEBUG_BYTECODE   8
#ifdef NDEBUG
#ifdef MEMDEBUG
#define DEBUG_MEMORY     16
#define DEBUG_STACK      32
#define DEBUG_MAX        63
#else
#define DEBUG_MAX        15
#endif
#else
#ifdef MEMDEBUG
#define DEBUG_INTERPRET  16
#define DEBUG_MEMORY     32
#define DEBUG_STACK      64
#define DEBUG_MAX        127
#else
#define DEBUG_INTERPRET  16
#define DEBUG_MAX        31
#endif
#endif

// Debugging console
#define DEBUG_BUFFER_SIZE 1024
#define CONSOLE_PROMPT "GCSx> "
#define CONSOLE_LENGTH 6

// File types; each type remembers the last directory used
// and has associated extension(s)
enum {
    FILETYPE_WORLD = 0,
    FILETYPE_IMAGE,
    FILETYPE_MODULE,
    FILETYPE_COUNT,
};

void initFileExtensions(std::vector<std::string>* fileExtensions);

// Filenames used for various things
#define FILENAME_ICON           "gcsxicon.bmp"
#define FILENAME_CFG            "gcsx.cfg"
#define FILENAME_TREEICONS      "treeicon.bmp"
#define FILENAME_EDITORICONS    "editoricon.bmp"
#define FILENAME_BKFRONT        "gcsx_bk.png"
#define FILENAME_BKEDITOR       "gcsx_bk2.png"
#define FILENAME_COLORICONS     "coloricon.bmp"

// Config settings- assigned static values as they
// should not ever change, for upwards compatibility
enum {
    CONFIG_NO_SETTING = 0,

    // Numeric settings
    VIDEO_X = 1,
    VIDEO_Y = 2,
    VIDEO_BPP = 3,
    VIDEO_FULLSCREEN = 4,
    VIDEO_RESIZABLE = 12,

    TILEPAINT_ZOOM = 5,
    TILEPAINT_ANTIALIAS = 6,
    TILEPAINT_TOLERANCE = 7,
    TILEPAINT_GRID = 8,
    TILEPAINT_DOTS = 9,

    LAYEREDIT_GRID = 11,

    ANIMEDIT_OUTLINE = 13,

    RGBSELECT_METHOD = 10,
    
    WARN_GAMEMENU = 14,

    FRONTEND_ACTIVE_ALPHA = 15,
    FRONTEND_INACTIVE_ALPHA = 16,
    FRONTEND_ACTIVE_BKALPHA = 17,
    FRONTEND_INACTIVE_BKALPHA = 18,
    
    LINKED_RETAIN = 19,
    LINKED_PREGENERATE = 20,
    
    // Numeric settings that aren't saved to file
    // Features marked with * should not be modified outside of testing/debugging
    CONFIG_FIRST_VOLATILE_SETTING = 8192,
    
    OGL_MIN_SIZE = 8192, // *
    OGL_MAX_SIZE = 8193, // *
    OGL_POWER_OF_TWO = 8194, // * Texture sizes must be ^2
    OGL_FORCE_SINGLE = 8195, // Never use sub-textures
    OGL_PREFER_GROUPING = 8196, // Use a single large texture for graphic sets when possible
                                // (otherwise, aims for most efficient texture mem usage)
                                // Overridden by OGL_FORCE_SINGLE

    // String settings
    CONFIG_FIRST_STRING_SETTING = 16384,
    CONFIG_LAST_STRING_SETTING = 32767,

    // Shortcut keys- add this to command code
    CONFIG_ADD_SHORTCUT = 32768,

    // For each alternate shortcut key, add this
    CONFIG_ADD_SHORTCUT_ALTERNATE = 4096,

    // Max number of alternates, in addition to main key
    // One less than the theoritical max to prevent potential wrap
    // around when doing math
    CONFIG_MAX_SHORTCUT_ALTERNATE = 6,

    // Max total settings- 16bits, but we discard the last 4096
    // sinc we only want max 7 shortcut keys per
    CONFIG_MAX_SETTING = 61439,
};

void initConfigDefaults(std::map<Uint16, Sint32>& configN);

// Default shortcut keys
struct defaultShortcut {
    Uint16 cmd;
    Uint16 mod;
    Uint16 key;
};
extern const defaultShortcut shortcutDefault[];

// SDL_OBJECTCHANGE constants
enum {
    // Masks
    OBJMASK_TYPE   = 0x00000FFF, // Type of object modified
    OBJMASK_MOD    = 0xFFFFF000, // Type of modification
    
    // Objects that can update
    OBJ_WORLD      = 0x00000001,
    OBJ_TILESET    = 0x00000002,
    OBJ_SCENE      = 0x00000004,
    OBJ_LAYER      = 0x00000008,
    OBJ_ANIMGROUP  = 0x00000010,
    OBJ_SCRIPT     = 0x00000020,
    OBJ_SPAWN      = 0x00000040,
    OBJ_FOLDER     = 0x00000080,
    
    // Object modifications
    // All objects
    OBJMOD_DELETE  = 0x00001000, 
    OBJMOD_NAME    = 0x00002000, 
    OBJMOD_CREATE  = 0x00004000, 
    
    // OBJ_WORLD
    OBJMOD_START   = 0x00008000,

    // OBJ_TILESET
    OBJMOD_WIDTH   = 0x00008000, // this also means all tiles have modified
    OBJMOD_HEIGHT  = 0x00010000, // this also means all tiles have modified 
    OBJMOD_COUNT   = 0x00020000, 
    OBJMOD_COUNTCOLL=0x00040000,
    OBJMOD_DEFTRANS= 0x00080000,
    OBJMOD_TILE    = 0x00100000, // info set to first tile mod; info2 last tile (never tile 0)
    OBJMOD_COLL    = 0x00200000, // info set to first coll mod; info2 last coll (never coll 0)
    OBJMOD_PERLINE = 0x00400000,
    OBJMOD_GLYPHW  = 0x00800000, // info set to tile number modified

    // OBJ_SCENE
    OBJMOD_LAYERADD= 0x00008000, // info set to pos of layer added (all layers at or above moved)
    OBJMOD_LAYERDEL= 0x00010000, // info set to old pos of layer removed (all layers above moved)
    OBJMOD_LAYERMOVE=0x00020000, // info and info2 set to pos of layers swapped

    // OBJ_LAYER
    //OBJMOD_WIDTH   0x00008000, 
    //OBJMOD_HEIGHT  0x00010000, 
    OBJMOD_TYPE    = 0x00020000,
    OBJMOD_USESEXT = 0x00040000, // (LAYER_TILE)
    OBJMOD_USESFX  = 0x00080000, // (LAYER_TILE)
    OBJMOD_TILES   = 0x00100000, // (LAYER_TILE) includes effects layer changes
    OBJMOD_TILESET = 0x00200000, // (LAYER_TILE)

    // OBJ_ANIMGROUP
    OBJMOD_ANIM    = 0x00008000, // An animation sequence (any part of it)
    
    // OBJ_SCRIPT
    // (line numbers are 0-based)
    OBJMOD_LINE    = 0x00008000, // info set to first line modified; info2 number of lines
    OBJMOD_INSERT  = 0x00010000, // info set to first line; info2 number of lines inserted
    OBJMOD_REMOVE  = 0x00020000, // info set to first line; info2 number of lines deleted
    OBJMOD_DEFAULT = 0x00040000,
    
    // OBJ_SPAWN
    OBJMOD_POS     = 0x00008000,
    OBJMOD_SCRIPT  = 0x00010000,
    OBJMOD_IMAGE   = 0x00020000,
    
    // OBJ_FOLDER
    OBJMOD_CONTENT = 0x00008000, // Any add, remove, move within
};

// Token types and subtypes
enum {
    TOKEN_NONE = 0,
    TOKEN_ENDLINE,
    TOKEN_IDENTIFIER,
    TOKEN_INTEGER,
    TOKEN_HEX,
    TOKEN_DECIMAL,
    TOKEN_STRING,
    TOKEN_STRINGTYPE,
    TOKEN_CONFIG,
    TOKEN_RESERVED,
    TOKEN_UNKNOWN,
    TOKEN_COMMENT_LINE, // Used internally only
    TOKEN_COMMENT_BLOCK, // Used internally only

    TOKEN_OPEN_BRACE,
    TOKEN_CLOSE_BRACE,
    TOKEN_OPEN_PAREN,
    TOKEN_CLOSE_PAREN,
    TOKEN_OPEN_BRACKET,
    TOKEN_CLOSE_BRACKET,
    TOKEN_COMMA,
    TOKEN_NAMESPACE, // colon colon ::
    TOKEN_LABEL, // colon :

    // Types with subtypes; primary type is designed to be a bitflag
    TOKEN_KEYWORD = 256,
    KEYW_ARRAY,
    KEYW_HASH,
    KEYW_STR,
    KEYW_INT,
    KEYW_FLOAT,
    KEYW_VAR,
    KEYW_GLOBAL,
    KEYW_LOCAL,
    KEYW_PRIVATE,
    KEYW_PUBLIC,
    KEYW_CONST,
    KEYW_VOID,
    KEYW_OBJ_ENTITY,
    KEYW_OBJ_SPRITE,
    KEYW_OBJ_SCENE,
    KEYW_RETURN,
    KEYW_IF,
    KEYW_ELSE,
    KEYW_TRUE,
    KEYW_FALSE,
    KEYW_QUERY,
    KEYW_FOR,
    KEYW_TO,
    KEYW_WITH,
    KEYW_FOREACH,
    KEYW_IN,
    KEYW_DO,
    KEYW_WHILE,
    KEYW_UNTIL,
    KEYW_BREAK,
    KEYW_CONTINUE,
    KEYW_RESTART,
    KEYW_REPEAT,
    KEYW_END,
    KEYW_REPLY,
    KEYW_STATE,
    KEYW_DEFAULT,
    KEYW_ALL,
    KEYW_ALL_OTHER,
    KEYW_THIS,
    KEYW_SOURCE,
    KEYW_NOTHING,
    KEYW_EXTEND,
    KEYW_IMPORT,
    KEYW_DEBUG,
    KEYW_IDLE,

    TOKEN_OPERATOR = 512,
    OPER_CONCAT,
    OPER_B_NOT, // twos complement (binary negation)
    OPER_L_NOT,
    OPER_MULT,
    OPER_DIV,
    OPER_PLUS, // or positive
    OPER_MINUS, // or negative
    OPER_MOD,
    OPER_LSHIFT,
    OPER_RSHIFT,
    OPER_B_AND,
    OPER_B_OR,
    OPER_B_XOR,
    OPER_LT,
    OPER_LE,
    OPER_GT,
    OPER_GE,
    OPER_EQ,
    OPER_NE,
    OPER_IS,
    OPER_AS,
    OPER_L_AND,
    OPER_L_OR,
    OPER_L_XOR,
    OPER_ASSIGN,
    OPER_MEMBER, // period .
};

#define WHITE_SPACE " \t"

// Fonts
enum {
    FONT_STANDARD = 0,
    FONT_MONO,
    FONT_WIDGET,
    FONT_TITLEBAR,
    FONT_TITLEBARWIDGET,
    FONT_TOOLTITLEBAR,
    FONT_TOOLTITLEBARWIDGET,
    FONT_TOOLTIP,
    FONT_MENU,
    FONT_COUNT,
};

struct FontInfo {
    const char* file;
    int size;
    TTF_Font* font;
    int height;
    int ascent;
};

extern FontInfo fonts[FONT_COUNT];

#endif
